<?php

namespace App\Http\Controllers\Manage;

use App\Helpers\ResponseData;
use App\Http\Controllers\Controller;
use App\Models\WorkOverTime;
use Illuminate\Http\Request;

class WorkOverTimeController extends Controller
{
    use ResponseData;
    public function list(WorkOverTime $model,Request $request){
        $user = $request->user();
        $model = $model
            ->with('one','two','three');
        if($user->department_two_id>0){
            $model = $model->select('id','department_one_id','department_two_id',
                'department_three_id','sub_account','service_customer','start','end','part_price','status','created_at','updated_at','price');
        }else{
            $model = $model->select('id','department_one_id','department_two_id',
                'department_three_id','sub_account','service_customer','start','end','part_price','status','created_at','updated_at','price');
        }
        $data = $model->orderBy('id','desc')->get();
        return $this->success($data);
    }
    public function store(WorkOverTime $model,Request $request){
        $data = $request->all();
        $model->fill($data);
        $model->save();
        return $this->success('保存成功');
    }
    public function edit(WorkOverTime $model,Request $request){
        $data = $model->find($request->id);
        return $this->success($data);
    }
    public function update(WorkOverTime $model,Request $request){
        $data = $model->find($request->id);
        $data->update($request->all());
        return $this->success('修改成功');
    }
    public function destory(WorkOverTime $model,Request $request){
        $data = $model->find($request->id);
        $data->delete();
    }
}
